/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.jaytter.ui.account;

import javax.swing.JPanel;
import org.jaytter.ui.manager.account.JaytterUIAccountManager;

/**
 * Project: JayTTer: A CrossPlatform Twitter Client
 * File name: MainWindow.java
 * Description:  This is a window for general use.
 *
 * @see The GNU Public License (GPL) v3
 */
public class AccountTimelineContainer extends javax.swing.JFrame {

    /** Creates new form MainWindow */
    public AccountTimelineContainer() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        globalContainer = new javax.swing.JPanel();
        tabsContainer = new javax.swing.JPanel();
        buttonPublicTimeline = new javax.swing.JButton();
        buttonRetweet = new javax.swing.JButton();
        buttonMentioned = new javax.swing.JButton();
        buttonDirectMessage = new javax.swing.JButton();
        tabsPanelScroll = new javax.swing.JScrollPane();
        tabsPanel = new javax.swing.JPanel();
        painelTweet = new javax.swing.JPanel();

        jLabel1.setText("jLabel1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Jaytter - Twitter Client");
        setMinimumSize(new java.awt.Dimension(500, 600));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        globalContainer.setBackground(new java.awt.Color(255, 153, 255));
        globalContainer.setLayout(new java.awt.BorderLayout());

        tabsContainer.setPreferredSize(new java.awt.Dimension(50, 572));

        buttonPublicTimeline.setText("PT");
        buttonPublicTimeline.setToolTipText("Timeline Pública");
        buttonPublicTimeline.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonPublicTimelineActionPerformed(evt);
            }
        });
        tabsContainer.add(buttonPublicTimeline);

        buttonRetweet.setText("RT");
        buttonRetweet.setToolTipText("Seus Tweets, Retuitados");
        buttonRetweet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonRetweetActionPerformed(evt);
            }
        });
        tabsContainer.add(buttonRetweet);

        buttonMentioned.setText("MEN");
        buttonMentioned.setToolTipText("Tweets mensionando você");
        buttonMentioned.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonMentionedActionPerformed(evt);
            }
        });
        tabsContainer.add(buttonMentioned);

        buttonDirectMessage.setText("DM");
        buttonDirectMessage.setToolTipText("Direct Messages para você");
        buttonDirectMessage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonDirectMessageActionPerformed(evt);
            }
        });
        tabsContainer.add(buttonDirectMessage);

        globalContainer.add(tabsContainer, java.awt.BorderLayout.LINE_START);

        tabsPanelScroll.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        tabsPanelScroll.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        tabsPanel.setLayout(new java.awt.BorderLayout());
        tabsPanelScroll.setViewportView(tabsPanel);

        globalContainer.add(tabsPanelScroll, java.awt.BorderLayout.CENTER);

        painelTweet.setPreferredSize(new java.awt.Dimension(300, 100));
        painelTweet.setLayout(new java.awt.BorderLayout());

        painelTweet.add( new AccountTweetForm(), java.awt.BorderLayout.CENTER );

        globalContainer.add(painelTweet, java.awt.BorderLayout.NORTH);

        getContentPane().add(globalContainer, java.awt.BorderLayout.CENTER);

        getAccessibleContext().setAccessibleDescription("Jaytter Twitter Client");

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-435)/2, (screenSize.height-619)/2, 435, 619);
    }// </editor-fold>//GEN-END:initComponents

    public void setCurrentTimelinePanel(JPanel timelinePanel) {
//        tabsPanel.removeAll(); //remove all antecessors
        System.out.println("[debug] adding panel timelinepanel to the frame");
        tabsPanel.removeAll();
        tabsPanel.validate(); //validates the remove

        tabsPanel.add(timelinePanel, java.awt.BorderLayout.CENTER);
        tabsPanel.repaint();
        tabsPanel.validate(); //validates the repaint (Java sucks)
    }
    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
    }//GEN-LAST:event_formWindowClosing

    private void buttonPublicTimelineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPublicTimelineActionPerformed
        changePanel(JaytterUIAccountManager.PANEL_PUBLIC_TIMELINE);
    }//GEN-LAST:event_buttonPublicTimelineActionPerformed

    private void buttonRetweetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRetweetActionPerformed
        changePanel(JaytterUIAccountManager.PANEL_RETWEETS);
    }//GEN-LAST:event_buttonRetweetActionPerformed

    private void buttonMentionedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMentionedActionPerformed
        changePanel(JaytterUIAccountManager.PANEL_MENTIONED);
    }//GEN-LAST:event_buttonMentionedActionPerformed

    private void buttonDirectMessageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectMessageActionPerformed
        changePanel(JaytterUIAccountManager.PANEL_DIRECTMESSAGES);
    }//GEN-LAST:event_buttonDirectMessageActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonDirectMessage;
    private javax.swing.JButton buttonMentioned;
    private javax.swing.JButton buttonPublicTimeline;
    private javax.swing.JButton buttonRetweet;
    private javax.swing.JPanel globalContainer;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel painelTweet;
    private javax.swing.JPanel tabsContainer;
    private javax.swing.JPanel tabsPanel;
    private javax.swing.JScrollPane tabsPanelScroll;
    // End of variables declaration//GEN-END:variables

    private void changePanel(String panelName) {
        System.out.println("[debug] changing ui timeline panel to " + panelName);
        JaytterUIAccountManager.getInstance().changeActiveTimelinePanel(panelName);
    }

    public JPanel getPainelTweet() {
        return painelTweet;
    }
}
